﻿using System;
using System.Collections.Generic;
using System.Text;
using Water.Architecture2.EntityXML;
using System.Web;
using System.IO;
using log4net.Config;

namespace Water.Web
{
    public class Application
    {
        private const string ENTITYCONFIGFIELD = "entity.xml";

        public static void Init()
        {
            //entity initialize
            EntityInit();
            //log4net load
            LogConfigLoad();
        }

        //entity initialize by entity config file,if entity config file is not found then  entity initialize by default config file 'entity.xml'
        private static void EntityInit()
        {
            string entityConfigField = Water.Util.Configuration.GetAppSetting("EntityConfigFile");
            if (string.IsNullOrEmpty(entityConfigField))
                entityConfigField = ENTITYCONFIGFIELD;

            string app_path = HttpContext.Current.Server.MapPath("~");
            app_path = app_path.EndsWith("\\") ? app_path : app_path + "\\";
            EntityFactory.Create(app_path, entityConfigField);
        }

        //log4net load
        private static void LogConfigLoad()
        {
            XmlConfigurator.Configure(new FileInfo("log4net.config"));
        }
    }
}
